package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.pubdef.dto.robottask.RobotTaskConfigDTO;
import com.qumitech.visualnovel.pubdef.dto.robottask.RobotTaskPresentInnerAccountNewDTO;
import com.qumitech.visualnovel.service.robottask.RobotTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/api/robottask")
public class RobotTaskController {
    @Autowired
    private RobotTaskService robotTaskService;

    @GetMapping(value = "/configs")
    public BaseRsp listConfig(){
        return robotTaskService.listTaskConfig();
    }

    @PostMapping(value = "/config")
    public BaseRsp saveConfig(@RequestBody RobotTaskConfigDTO configDTO){
        return robotTaskService.saveTaskConfig(configDTO);
    }

    @PutMapping(value = "/config")
    public BaseRsp updateConfig(@RequestBody RobotTaskConfigDTO configDTO){
        return robotTaskService.saveTaskConfig(configDTO);
    }

    @DeleteMapping(value = "/config")
    public BaseRsp rmConfig(@RequestBody RobotTaskConfigDTO configDTO){
        return robotTaskService.rmTaskConfig(configDTO.getTaskType(), configDTO.getConfigId());
    }

    @PostMapping(value = "/presentaccount")
    public BaseRsp savePresentAccount(@RequestBody RobotTaskPresentInnerAccountNewDTO newDTO){
        return robotTaskService.savePresentInnerAccount(newDTO);
    }

    @GetMapping(value = "/presentaccount")
    public BaseRsp listPresentAccount(@RequestParam(value = "uid", required = false) Long uid,
                                      @RequestParam(value = "present_id", required = false) String presentId,
                                      @RequestParam(value = "account_type", required = false) Byte accountType,
                                      @RequestParam(value = "offset",defaultValue = "0") Integer offset,
                                      @RequestParam(value = "limit",defaultValue = "20") Integer limit){
        return robotTaskService.listPresentInnerAccount(uid, presentId, accountType,offset,limit);
    }

    @DeleteMapping(value = "/presentaccount/{present_id}")
    public BaseRsp rmPresentAccount(@PathVariable("present_id") String presentId){
        return robotTaskService.rmPresentInnerAccount(presentId);
    }
}
